package cn.batchDelete;

import cn.GetPath.accessPath;
import cn.dto.BizConstant;
import cn.dto.Equipments;
import cn.hutool.http.HttpRequest;
import cn.pojo.longitudeAndLatitude;
import cn.utils.AnalysisExcel;
import cn.utils.GuideTable;
import cn.utils.ReadTxt;
import cn.utils.getLocation;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 添加经纬度上报物联基础数据
 */
public class writeEX {
    public static void main(String[] args)  {
        BizConstant bizConstant = ReadTxt.readFile(accessPath.getTxt());
        String upl_url = bizConstant.getUPL_URL();

        AnalysisExcel analysisExcel = new AnalysisExcel();

        ArrayList<cn.zyh.dto.BasicInformation> basicInformations = analysisExcel.ToAnalysisExcel(accessPath.getXls());
        System.out.println(basicInformations.size());

        basicInformations.forEach(e -> {
            System.out.println(e);//
            if (e.getSensorId()==null | e.getSensorId().equals("")){
                    return;
            }
            getLocation getLocation=new getLocation();
            try {
                longitudeAndLatitude location = getLocation.getLocation(e.getAddress());
                e.setWsLng(location.getLongitude());
                e.setWsLat(location.getLatitude());
            }catch (NullPointerException exception){

                System.out.println(e.getSensorId()+"的地址是空的");
            }
            //添加请求
            //删除
            /*
            Equipments equipments = new Equipments(e.getSensorId(), e.getSensorType(), e.getDataCode());
            String stuString = JSONObject.toJSONString(equipments);
              String resp = HttpRequest.delete("http:"+upl_url+":8000/api-projectdatamanage/equipmentsync").body("{\"equipments\":["+stuString+"]}").header("Authenticator", GuideTable.getSessionId(bizConstant)).execute().body();
                   System.out.println(resp);
             */

            //物联基础数据上报接口
            String resp =HttpRequest.post("http:"+upl_url+":8000/api-projectdatamanage/equipmentsync/sync").body("{["+JSONObject.toJSONString(e)+"]}").header("Authenticator", GuideTable.getSessionId(bizConstant)).execute().body();
            System.out.println(resp);
        });


    }
}
